package com.hoku.auth.controller;

import com.hoku.auth.model.User;
import com.hoku.auth.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.security.Principal;

/**
 * 用户信息控制器
 * @author ZHUFEIFEI
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("/info")
    public Principal currentUser(Principal principal) {
        return principal;
    }


    @PreAuthorize("#oauth2.hasScope('server')")
    @PostMapping
    public void createUser(@Valid @RequestBody User user) {
        this.userService.create(user);
    }

}
